package cn.dujc.superkid.activities;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
import android.view.inputmethod.InputMethodManager;

import cn.dujc.core.ui.BaseActivity;
import cn.dujc.core.util.ToastUtil;
import cn.dujc.superkid.R;
import cn.dujc.superkid.configs.ICallBack;
import cn.dujc.superkid.configs.SearchView;
import cn.dujc.superkid.configs.bCallBack;


public class SearchActivity extends BaseActivity {
    private SearchView searchView;
    private cn.dujc.superkid.configs.EditText_Clear et_search;
    private String searchContent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        去掉TitleBar（需要放到setContentView上面）
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_search);

        // 3. 绑定组件
        searchView = (SearchView) findViewById(R.id.search_view);
        et_search = findViewById(R.id.et_search);
        // 4. 设置点击搜索按键后的操作（通过回调接口）
        // 参数 = 搜索框输入的内容
        searchView.setOnClickSearch(new ICallBack() {
            @Override
            public void SearchAciton(String string) {
                searchContent=et_search.getText().toString();
                if (searchContent.isEmpty()){
                    ToastUtil.showToast(mActivity,"请输入课程关键字");
                    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
                }else {
                    starter()
                            .with(SearchResultActivity.EXTRA_COURSE,searchContent)
                            .go(SearchResultActivity.class);
                }

            }
        });

        // 5. 设置点击返回按键后的操作（通过回调接口）
        searchView.setOnClickBack(new bCallBack() {
            @Override
            public void BackAciton() {
                Intent intent  = new Intent(SearchActivity.this,MainActivity.class);
                startActivity(intent);
            }
        });

    }

    public void onResume() {
        super.onResume();
        searchView.queryData();
    }

    @Override
    public int getViewId() {
        return 0;
    }

    @Override
    public void initBasic(Bundle savedInstanceState) {

    }
}




